Skip to content

fix: eliminate unbounded memory leak in sliding-window rate limiters - #216

Merged
levibliz merged 2 commits into
RiftCore00:devfrom
almuslavish:blackboxai/fix-rate-limiter-memory-leak
Jul 30, 2026
Merged

fix: eliminate unbounded memory leak in sliding-window rate limiters#216
levibliz merged 2 commits into
RiftCore00:devfrom
almuslavish:blackboxai/fix-rate-limiter-memory-leak

Conversation

@almuslavish

Copy link
Copy Markdown
Contributor

closes #193

Replace O(n) Array.shift() with batch filter() in both check() methods. Add cleanup() method to both limiters for proactive stale entry eviction. Add size getter to both limiters for memory observability. Add remove() method to createConnRateLimiter for API parity.

The per-client rate limiter (1-second window) and per-IP connection rate limiter (60-second window) now:

  • Use batch filter() instead of shift() for O(1) amortized check()
  • Expose cleanup() to remove all stale entries in one pass
  • Expose size getter (windows.size) for monitoring
  • Remove keys entirely when no active timestamps remain

Closes: issue-03-rate-limiter-memory-leak

almuslavish and others added 2 commits July 27, 2026 16:26
Replace O(n) Array.shift() with batch filter() in both check() methods.
Add cleanup() method to both limiters for proactive stale entry eviction.
Add size getter to both limiters for memory observability.
Add remove() method to createConnRateLimiter for API parity.

The per-client rate limiter (1-second window) and per-IP connection rate
limiter (60-second window) now:
- Use batch filter() instead of shift() for O(1) amortized check()
- Expose cleanup() to remove all stale entries in one pass
- Expose size getter (windows.size) for monitoring
- Remove keys entirely when no active timestamps remain

Closes: issue-03-rate-limiter-memory-leak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eliminate the unbounded memory leak in sliding-window rate limiters by implementing time-bucketed eviction with amortized O(1) cleanup

2 participants